package mx.com.fractal.ristorante.rest;

import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import mx.com.fractal.ristorante.dto.ClienteDTO;
import mx.com.fractal.ristorante.dto.ErrorResponseDTO;
import mx.com.fractal.ristorante.service.ClienteService;

@Singleton
@Path("cliente")
public class ClienteRest {

	@EJB
	private ClienteService clienteService;
	
	@PUT
	@Path("save")
	@Consumes(value={MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
	@Produces(value={MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
	public Response save(ClienteDTO cliente){
		try {
			clienteService.save(cliente);
			return Response.ok().entity(cliente).build();
		} catch (Exception e) {
			ErrorResponseDTO error=new ErrorResponseDTO(e.getMessage());
			return Response.serverError().entity(error).build();
		}
		
	}
}
